package com.lw.sbdemo2.service;

import com.github.pagehelper.PageHelper;
import com.lw.sbdemo2.common.base.CrudService;
import com.lw.sbdemo2.common.exception.ApiException;
import com.lw.sbdemo2.common.vo.PageInfo;
import com.lw.sbdemo2.entity.TkGradeDict;
import com.lw.sbdemo2.mapper.TkGradeDictMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>标题: 年级字典服务 - 业务逻辑层</p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2019</p>
 * <p>公司: 山人行工作室</p>
 *
 * @version: 1.0
 * @author: Linqunyuan
 * @date 2019-5-25
 */
@Slf4j
@Service
public class TkGradeDictService extends CrudService<TkGradeDict, TkGradeDictMapper> {

	/**
     * 获取用户分页列表
     *
     * @param query    搜索关键词
     * @param pageInfo 分页实体
	 * @param tkGradeDict 实体入参
     * @return 用户列表
     */
    public PageInfo<TkGradeDict> findListPage(String query, PageInfo pageInfo, TkGradeDict tkGradeDict) {
        PageHelper.startPage(pageInfo);
        List<TkGradeDict> tkGradeDictlist = this.dao.findListPage(query, tkGradeDict);
        return new PageInfo<>(tkGradeDictlist);
    }


    /**
     * 校验代码是否存在
     *
     * @param code  代码
     * @return
     * @throws Exception
     */
    public void checkCode(String code) throws Exception {
        int count = this.dao.checkCode(code);
        if (count > 0) {
            throw new ApiException("代码已存在");
        }
    }

    /**
     * 校验名称是否存在
     *
     * @param name  名称
     * @return
     * @throws Exception
     */
    public void checkName(String name) throws Exception {
        int count = this.dao.checkName(name);
        if (count > 0) {
            throw new ApiException("名称已存在");
        }
    }

    /**
     * 更新校验名称是否存在
     *
     * @param name  名称
     * @return
     * @throws Exception
     */
    public void updateCheckName(String code,String name) throws Exception {
        int count = this.dao.updateCheckName(code,name);
        if (count > 0) {
            throw new ApiException("名称已存在");
        }
    }
	
}